﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Jemgine.Particles.Distributors
{
    public class Arc : Distributor
    {
        public FloatRange Angle { get; set; }
        public FloatRange Distance { get; set; }
        public FloatRange Velocity { get; set; }
        public bool AlignAngle { get; set; }

        public Arc()
        {
            Angle = new FloatRange(0, 360);
            Distance = new FloatRange(0, 0);
            Velocity = new FloatRange(1, 1);
            AlignAngle = false;
        }

        public override void SetEmission(Random _random, ref Particle _particle, float _emitterAngle)
        {
            float A = _emitterAngle + MathHelper.ToRadians(FloatRange.GetValue(Angle, _random));
            Matrix M = Matrix.CreateRotationZ(A);
            Vector2 Direction = Vector2.Transform(Vector2.UnitY, M);
            _particle.velocity = Direction * FloatRange.GetValue(Velocity, _random);
            _particle.position = Direction * FloatRange.GetValue(Distance, _random);
            if (AlignAngle) _particle.angle = -A;
        }
    }
}
